using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework.Config;
using DigitalFortress.Entities;
using DigitalFortress.Core;

namespace DigitalFortress.Testing.Agent {
	/// <summary>
	/// Test fixture to be used as base for all agent unit tests.
	/// </summary>
	[TestFixture]
	public abstract class BaseTestFixture {

		/// <summary>
		/// Setups the test fixture.
		/// </summary>
		[TestFixtureSetUp]
		public virtual void TestFixtureSetUp() {
			try {
				ActiveRecordStarter.Initialize(typeof(Entities.UserEntity).Assembly,
					ActiveRecordSectionHandler.Instance);
			}
			catch (System.Exception ex) {

			}
			try {
				log4net.Config.XmlConfigurator.Configure();
			}
			catch (System.Exception ex) {

			}
		}

		/// <summary>
		/// Tears Down the test fixture.
		/// </summary>
		[TestFixtureTearDown]
		public virtual void TestFixtureTearDown() {
			ActiveRecordStarter.DropSchema();
			ActiveRecordStarter.CreateSchema();
		}

		/// <summary>
		/// Setups each test.
		/// </summary>
		[SetUp]
		public virtual void SetUp() {
			ActiveRecordStarter.DropSchema();
			ActiveRecordStarter.CreateSchema();
			this.CreateBaseData();
			this.InitializeData();
		}

		/// <summary>
		/// Tears down each test.
		/// </summary>
		[TearDown]
		public virtual void TearDown() {

		}

		/// <summary>
		/// Initializes data for this test fixture.
		/// </summary>
		public abstract void InitializeData();

		/// <summary>
		/// Creates basic data as the digital fortress application, and some default users.
		/// </summary>
		private void CreateBaseData() {
			ObjectMother.CreateBasicApplicationData("DigitalFortress", "Digital Fortress administration application.", "heynemann@gmail.com");
			ObjectMother.CreateBasicApplicationData("SampleApp", "Sample Application.", "mickal@uol.com.br");
		}
	}
}
